-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix redirect on login for instances behind reverse proxies #6371
Conversation
On instances where base_url has been set for use behind a reverse proxy, logins are incorrectly redirected. This happens because REQUEST_URI is set by the proxy: 1. librenms has base_url set to http://site.com/nms/ 2. Browser requests http://site.com/nms/ 3. nginx reverse proxies /nms/ to librenms at http://somehost:1234/ 4. librenms sees REQUEST_URI as "/" 5. librenms logs the user in, but sends "Location: /" to the browser. This redirects to the wrong location. To resolve, concatenate REQUEST_URI (which is relative) to base_url. As base_url is slash-terminated, crop the trailing slash. This should have no effect on users with default settings and will correctly redirect instances behind reverse proxies.
…oc/General/Contributing.md.
Auto-Deploy finished, Test PR at http://6371.ci.librenms.org or https://6371.ci.librenms.org |
html/includes/authenticate.inc.php
Outdated
@@ -96,7 +96,8 @@ | |||
|
|||
$permissions = permissions_cache($_SESSION['user_id']); | |||
if (isset($_POST['username'])) { | |||
header('Location: '.$_SERVER['REQUEST_URI'] ?: $config['base_url'], true, 303); | |||
// Trim the trailing slash off of base_url and concatenate the (relative) REQUEST_URI | |||
header('Location: '.substr($config['base_url'], 0, -1).$_SERVER['REQUEST_URI'], true, 303); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This variable does not always have a slash at the end.
Please add a sanity check before cutting off a character from the base_url; worst case you kill the tld.
Probably easier to just do something like rtrim($val, '/'); |
Good catch. I didn't realize rtrim had that character mask param. Looks like that is both cleaner and solves the use case where there's no trailing slash. |
Auto-Deploy finished, Test PR at http://6371.ci.librenms.org or https://6371.ci.librenms.org |
The inspection completed: No new issues |
On instances where base_url has been set for use behind a reverse proxy, logins are incorrectly redirected.
This happens because REQUEST_URI is set by the proxy:
To resolve, concatenate REQUEST_URI (which is relative) to base_url. As base_url is slash-terminated, crop the trailing slash. This should have no effect on users with default settings and will correctly redirect instances behind reverse proxies.
DO NOT DELETE THIS TEXT
Please note
Testers
If you would like to test this pull request then please run:
./scripts/github-apply <pr_id>
, i.e./scripts/github-apply 5926